import DList from "@/components/dlist";
export default {
  data() {
    return {
      showPopover: false,
      actions: [
        { text: "商品名" , value: "goods_title"}, 
        { text: "订单号" , value: "order_sn"},
        { text: "会员信息" , value: "member_kwd"},
      ],
      search_column: { text: "会员信息" , value: "member_kwd"}, 
      loading: false,
      finished: false,
      page: 1,
      dataList: []
    };
  },
  mounted() {
    this.id = this.$route.params.id;
    this.getData();
  },
  methods: {
    onSelect(value) {
      this.search_column = value;
      this.searchData();
    },
    async getData(val) {
      if (this.loading === true || this.finished === true) {
        return;
      }
      this.loading = true;
      let { data, result, msg } = await $http.post("plugin.region-external-reward.frontend.controllers.client.client.childOrderList", { 
        child_id: this.id,
        page: this.page,
        keyword: this.keyword,
        search_column: this.search_column.value
      });
      if (result) {
        if(val == "loading") {
          this.dataList.push(...data.list.data);
        }else {
          this.dataList = data.list.data;
        }
        if (data.list.data.length === 0 || data.list.data.length < data.list.per_page || data.list.current_page === data.list.last_page) {
          this.finished = true;
        }
        for(let item of this.dataList) {
          if(item.order_goods.length) {
            item.total = 0;
            for(let citem of item.order_goods) {
              item.total = item.total + citem.total
            }
          }
        }
        this.page++;
        this.loading = false;
      } else {
        this.$toast(msg);
      }
    },
    onLoad() {
      this.getData("loading");
    },
    searchData() {
      clearTimeout(this.timer);
      this.timer = setTimeout(() => {
        this.dataList = [];
        this.loading = false;
        this.finished = false;
        this.page = 1;
        this.getData(); //防抖
      }, 300);
    }
  },
  components: { DList }
};
